<template>
  <div style="padding:30px 25%;">
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="12">
          <el-form-item label="发放类型" prop="field102">
            <el-select v-model="formData.field102" placeholder="请选择发放类型" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in field102Options" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否启用" prop="status">
            <el-select v-model="formData.status" placeholder="请选择是否启用" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in statusList" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="优惠券类型" prop="couponType">
            <el-select v-model="formData.couponType" placeholder="请选择优惠券类型" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in couponTypelist" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商家名称" prop="mmid">
            <el-select v-model="formData.mmid" placeholder="请选择商家名称" clearable :style="{width: '100%'}">
              <el-option v-for="(item, index) in merchantList" :key="index" :label="item.label"
                         :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="优惠券名称" prop="couponName">
            <el-input v-model="formData.couponName" placeholder="请输入优惠券名称" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="发行数量" prop="couponAduitNum">
            <el-input-number v-model="formData.couponAduitNum" placeholder="请输入发行数量" controls-position=right>
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="剩余库存" prop="couponInventoryNum">
            <el-input-number v-model="formData.couponInventoryNum" placeholder="请输入剩余库存" controls-position=right>
            </el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="获取限制" prop="accessRestriction">
            <el-input v-model="formData.accessRestriction" placeholder="请输入获取限制" clearable :style="{width: '100%'}">
              <template slot="append">张</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="优惠金额" prop="couponPrice">
            <el-input v-model="formData.couponPrice" placeholder="请输入优惠金额" clearable :style="{width: '100%'}">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="生效时长" prop="effectiveDuration">
            <el-input v-model="formData.effectiveDuration" placeholder="请输入生效时长" clearable :style="{width: '100%'}">
              <template slot="append">天</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="field113">
            <el-input v-model="formData.field113" type="textarea" placeholder="请输入备注"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">返回</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import { listManagement, getManagement, delManagement, addManagement, updateManagement } from "@/api/modules/merchat/coupon/coupon";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        field102: undefined,
        field103: undefined,
        field104: undefined,
        field105: undefined,
        field106: undefined,
        field107: undefined,
        field108: 61,
        field109: undefined,
        field110: undefined,
        field111: undefined,
        field113: undefined,
      },
      rules: {
        field102: [{
          required: true,
          message: '请选择发放类型',
          trigger: 'change'
        }],
        field103: [{
          required: true,
          message: '请选择是否启用',
          trigger: 'change'
        }],
        couponType: [{
          required: true,
          message: '请选择优惠券类型',
          trigger: 'change'
        }],
        mmid: [{
          required: true,
          message: '请选择商家名称',
          trigger: 'change'
        }],
        field106: [{
          required: true,
          message: '请输入优惠券名称',
          trigger: 'blur'
        }],
        field107: [{
          required: true,
          message: '请输入发行数量',
          trigger: 'blur'
        }],
        field108: [{
          required: true,
          message: '请输入剩余库存',
          trigger: 'blur'
        }],
        field109: [{
          required: true,
          message: '请输入获取限制',
          trigger: 'blur'
        }],
        field110: [{
          required: true,
          message: '请输入优惠金额',
          trigger: 'blur'
        }],
        field111: [{
          required: true,
          message: '请输入生效时长',
          trigger: 'blur'
        }],
        field113: [{
          required: true,
          message: '请输入备注',
          trigger: 'blur'
        }],
      },
      field102Options: [{
        "label": "平台发放",
        "value": 1
      }, {
        "label": "商家发放",
        "value": 2
      }],
      statusList: [{
        "label": "启用",
        "value": 1
      }, {
        "label": "禁用",
        "value": 0
      }],
      couponTypelist: [{
        "label": "金额减免券",
        "value": "金额减免券"
      }, {
        "label": "全免券",
        "value": "全免券"
      }],
      merchantList: [
        {
          "label": "洗车场",
          "value": 1
        }
      ],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      // this.$refs['elForm'].validate(valid => {
      //   if (!valid) return
        // TODO 提交表单
        addManagement(this.formData).then(respon=>{
          this.$store.dispatch('tagsView/delAllViews',this.$router);
          this.$router.push("coupon")
        })
      // })
    },
    resetForm() {
      this.$store.dispatch('tagsView/delAllViews',this.$router);
      this.$router.push("coupon")
    },
  }
}

</script>
<style>
</style>
